package org.mushroomdb.transaction;

import org.mushroomdb.parser.Parser;
import org.mushroomdb.parser.ParserException;
import org.mushroomdb.query.Query;
import org.mushroomdb.security.SecurityService;
import org.mushroomdb.service.ServiceManager;

/**
 * @author Tomas
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TransactionalParser implements Parser {

    /* (non-Javadoc)
     * @see org.mushroomdb.parser.Parser#parseQuery(java.lang.String)
     */
    public Query parseQuery(String query) throws ParserException {
        return new TransactionalQuery(query);
    }

    public boolean accepts(String query) {
        String query2 = query.trim();
        
        if (("COMMIT ;").equalsIgnoreCase(query2) || ("ROLLBACK ;").equalsIgnoreCase(query2)){
            return true;
        }
        else if(query2.toUpperCase().equalsIgnoreCase("BEGIN TRANSACTION ;")){
            return true;
        }
        else
            return false;
     }

}
